<?php
include "../../../lib/list.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../../css/list.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/insert.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/table.sorter.css" type="text/css" media="print, projection, screen" />
<link type="text/css" rel="stylesheet" href="../../../css/dhtmlgoodies_calendar.css?random=20051112" media="screen"></link>

<script type="text/javascript" src="../../../js/dhtmlgoodies_calendar.js?random=20060118"></script>
<script type="text/javascript" src="../../../js/list.js"></script>
<script type="text/javascript" src="../../../js/jquery-1.2.6.js"></script>
<script type="text/javascript">
function addRow(){	
 var template = $("#template"); // 필요없는데... 일단은 혹시 모르니까 
 var form = document.stocktaking;
 if(!form.ibarcode.value){
	 alert('바코드를 입력해주세요.');
	 form.ibarcode.focus();
	 return;
 }if(!form.icount.value){
	 alert('갯수를 입력해주세요.');
	 form.icount.focus();
	 return;
}

 var chbarcode	= 	document.getElementsByName('barcode[]');
	 for(i=0;i<chbarcode.length;i++){
		if(chbarcode[i].value==form.ibarcode.value){
			alert('이미 입력하신 제품입니다.');
			 form.ibarcode.value = "";
			 form.icount.value = "";
			 form.ibarcode.focus();
			 return;
			}
	}

	var s_no = document.getElementsByName('s_no')[0].value;
 	$.get('../../../lib/select.php?ibarcode='+form.ibarcode.value+'&icount='+form.icount.value+'&s_no='+s_no, 

 function(template){
	 $("#tablesorter").prepend(template);
	 }
 );
 form.ibarcode.value = "";
 form.icount.value = "";
 form.ibarcode.focus();
}

function deleteRow(obj){
 $(obj).parent().remove();
}

function submit(){
	document.stocktaking.mode.value 	 = 'insert';
	document.stocktaking.target			 = 'right';
	document.stocktaking.action			 = 'query.php';
	document.stocktaking.method			 = 'post';
	document.stocktaking.submit();
}

$(function(){
    $("select[name='sg_no']").change(function(){
	    var sg_no = $("select[name='sg_no']").attr('value');
	    $.get('../../../lib/select.php?sg_no='+sg_no,function(res){
	        $("select[name='s_no']").html(res);
	    });
	});
	
	$("select[name='s_no']").change(function(){
        $("#tablesorter tbody tr").remove();
		});  
});
</script>
</head>
<body>
	<div style="width: 1024px;">
		<div
			style="border-bottom: 1px solid #e8e8e8; text-align: left; font-size: 12px; margin-bottom: 12px; color: #9a9a9a">:::
			재고 관리&nbsp;⇒&nbsp;재고조사입력</div>
		<form name="stocktaking" method="post" action="query.php" enctype=multipart/form-data>
						<input name="mode" value="insert" type="hidden"/>
						<input type="hidden" name="page" value=""/>
			<table cellspacing="1" class="tablesorter" id="tablesorter" style="width:750px;float:right;">
			<thead>
					<tr>
						<th>barcode</th>
						<th>상품 명</th>
						<th>현수량</th>
						<th>조사수량</th>
						<th>차이수</th>
						<th></th>
					</tr>
					<tr style="background:#efefef;">
					<td style="width:150px;"><input type='text' name='ibarcode' value="" class="default" style="width:150px;" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"/></td>
					<td style="width:300px;"></td>
					<td></td>
					<td style="width:70px;"><input type='text' name='icount' value='' class="default" style="text-align:right;width:70px;" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')">
					</input></td>
					<td></td>
					<td style='text-align:center;'><a href="javascript:addRow()">추가</a></td>
					</tr>
					</thead>
					<tbody>
					</tbody>
		</table>
			<div style="width:250px;float:left;">
			<table class="entry fixed H_15px" summary="재고-입력상단부">
						<tr>
								<th style="width:30%">관리자</th>
								<td><?=$_SESSION['IS_NAME']?></td>
						</tr>
						  <tr>
						      <th style="width:30%">점포그룹</th>
						      <td>
						<select name='sg_no' class="default" style="width:160px;">
						<option value="-3">:: 점포그룹 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_shopgroup order by no DESC";
						$query = DBquery($qry);
						while($list = mysql_fetch_array($query)){
							?>
						<option value="<?=$list['no']?>"><?=$list['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
					</td>
						</tr>
						<tr>
						      <th style="width:30%">점포명</th>
						      <td>
						<select name='s_no' class="default" style="width:160px;">
							<option value="">:: 점포 선택 ::</option>
						</select>
						</td>
						</tr>
						</table>
									
						<div style="padding-top:15px;width:250px;float:right;">
						<center><a href="javascript:submit()" class="button blue small" style="width:150px;">&nbsp;입력하기&nbsp;</a></center>
						</div>	
						</div>					
					
			</form>
	</div>
</body>
</html>
